import cn.edu.zut.cs.dao.StudentDao;
import cn.edu.zut.cs.impl.StudentDaoImpl;
import cn.edu.zut.cs.model.Student;

import java.sql.SQLException;

public class DaoPatternDemo {
    public static void main(String[] args) throws SQLException {
        StudentDao studentDao = new StudentDaoImpl();

        //添加学生
        System.out.println("添加学生");
        studentDao.addStudent(new Student("test2",50));
        studentDao.addStudent(new Student("test3",51));

        //输出所有的学生
        System.out.println("输出所有的学生");
        for (Student student : studentDao.getAllStudents()) {
            System.out.println("Student: [RollNo : "
                    +student.getRollNo()+", Name : "+student.getName()+" ]");
        }


        //更新学生
        System.out.println("修改学生");
        Student student =studentDao.getStudent(50);
        student.setName("Michael");
        studentDao.updateStudent(student);

        //获取学生
        System.out.println("查询学生");
        Student st= studentDao.getStudent(50);
        System.out.println("Student: [RollNo : "
                +st.getRollNo()+", Name : "+st.getName()+" ]");

        //删除学生
        System.out.println("删除学生");
        Student de_st=studentDao.getStudent(50);
        studentDao.deleteStudent(de_st);
        //删除学生
        System.out.println("删除学生");
        Student de_st1=studentDao.getStudent(51);
        studentDao.deleteStudent(de_st1);
    }
}